package com.zzty.txj.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.zzty.txj.dao.ReportMapper;
import com.zzty.txj.entity.Daily;
import com.zzty.txj.entity.DoDaily;
import com.zzty.txj.entity.User;
import com.zzty.txj.service.ReportService;
import com.zzty.txj.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportMapper reportMapper;
    public List<DoDaily> dodaily(Integer userId,String date1,String date2){

        List<DoDaily>doDailies=reportMapper.dodaily(userId,date1,date2);
        return doDailies;
    }
    public String getSubjectName(Integer id){
        String name=reportMapper.getSubjectName(id);
        return name;
    }

    @Value("${url.user.getUserById}")
    String url1;

    @Override
    public String getName(Integer id){
        User user = null;
        String result = null;
        try {
            result = HttpUtil.httpGet(url1 + id);
            user=JSONObject.parseObject(result,User.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user.getName();
    }

//    public String getName(Integer id){
//        String name=reportMapper.getName(id);
//        return name;
//    }

    public Integer count(Integer userId,String date1,String date2,Integer dailyId){
        Integer count=reportMapper.count(userId,date1,date2,dailyId);
        return count;
    }
    public Integer counts(Integer userId,String date1,String date2,Integer dailyId){
        Integer count =reportMapper.counts(userId,date1,date2,dailyId);
        return count;
    }
    public String dailyId(Integer userId){
        String dailyId=reportMapper.dailyId(userId);
        return dailyId;
    }

}
